package cn.shujuhai.workflow.util;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.mail.SimpleMailMessage;
import org.springframework.mail.javamail.JavaMailSender;
import org.springframework.stereotype.Component;

// 单独的邮件工具类
@Component
public class EmailUtil {
    private static JavaMailSender mailSender;
    private static String mailFrom; // 添加发件人配置

    @Autowired
    public void setMailConfig(JavaMailSender mailSender,
                              @Value("${spring.mail.username}") String mailFrom) {
        EmailUtil.mailSender = mailSender;
        EmailUtil.mailFrom = mailFrom;
    }

    public static void sendRejectionEmail(String to, String reason) {
        SimpleMailMessage message = new SimpleMailMessage();
        message.setFrom(mailFrom);
        message.setTo("2215580545@qq.com");
        message.setSubject("请假申请被拒绝");
        message.setText("您的请假申请已被拒绝!");
        mailSender.send(message);
    }
}